<?php


/**
 * @author fyl
 * Date: 16-3-29 下午2:59
 */

class ShopService extends BaseService
{
    private static $self       =   NULL;
    private $mCategory                      =   NULL;
    private $mSpecificate                   =   NULL;
    private $mShopProduct                   =   NULL;
    private $mShopBusiness                  =   NULL;
    private $mShopCart                      =   NULL;
    private $mShopad                        =   NULL;




    static public function instance()
    {
        if (self::$self == NULL) {
            self::$self = new self;
        }
        return self::$self;
    }


    public function __construct()
    {

        $this->mCategory                  =   new  Involved_ShopModel();
        $this->mSpecificate               =   new  Involved_SpecifiModel();
        $this->mShopProduct               =   new  Involved_ShopProductModel();
        $this->mShopCart                  =   new  Involved_ShopCartModel();
        $this->mShopBusiness              =   new  Involved_ShopBusinessModel();
        $this->mShopad                    =   new  Involved_ShopAdsModel();

    }
    /**
     * 首页分类
     * @return mixed
     */
    public function CatesList()
    {
        return $this->mCategory->CatesList();
    }
    public function SelectCategory($id,$fids){

        return $this->mCategory->SelectCategory($id,$fids);
    }
    public function SelectCategorys($id){

        return $this->mCategory->SelectCategorys($id);
    }
    /**
     *1F木材
     */
    public function MuCaiList()
    {
        return $this->mCategory->MuCaiList();
    }
    /**
     *商家
     */
    public function BusinList($id,$fids)
    {
        return $this->mCategory->BusinList($id,$fids);
    }
    public function SelectCategoryes($id,$fids){

        return $this->mCategory->SelectCategoryes($id,$fids);
    }










    /**
     * 商品列表
     * @return mixed
     */
    public function YptShopList()
    {
        return $this->mShopProduct->YptShopList();
    }

    /**
     * 商品列表分类
     * @param $c_id
     * @return mixed
     */
    public function YptShopListSort($c_id)
    {
        return $this->mCategory->YptShopListSort($c_id);
    }

    /**
     * 搜索
     * @param $keywords
     * @param $stock
     * @param $mix_price
     * @param $max_price
     * @return mixed
     */
    public function YptShopListSearch($keywords,$stock,$mix_price,$max_price)
    {
        return $this->mShopProduct->YptShopListSearch($keywords,$stock,$mix_price,$max_price);
    }

    public function YptShopListOrderSearch($keywords,$id,$stock,$mix_price,$max_price)
    {
        return $this->mShopProduct->YptShopListOrderSearch($keywords,$id,$stock,$mix_price,$max_price);
    }

    public function YptShopListOrder($id,$stock,$mix_price,$max_price)
    {
        return $this->mShopProduct->YptShopListOrder($id,$stock,$mix_price,$max_price);
    }

    public function YptShopListOrderSortSearch($c_id,$id,$stock,$mix_price,$max_price)
    {
        return $this->mShopProduct->YptShopListOrderSortSearch($c_id,$id,$stock,$mix_price,$max_price);
    }

    public function YptShopListSortSearch($c_id,$stock,$mix_price,$max_price)
    {
        return $this->mShopProduct->YptShopListSortSearch($c_id,$stock,$mix_price,$max_price);
    }


    /**
     * 商家
     * @param $c_id
     * @return mixed
     */
    public function YptShopBusiness($c_id)
    {
        return $this->mShopProduct->YptShopBusiness($c_id);
    }
    public function YptShopBusinessList($arr)
    {
        return $this->mShopBusiness->YptShopBusinessList($arr);
    }




    /**
     * 商家列表
     * @return mixed
     */
    public function YptBusinessList()
    {
        return $this->mShopBusiness->YptBusinessList();
    }

    /**
     * 商家详情商品列表
     * @param $buisness_id
     * @return mixed
     */
    public function YptBusinessShopList($business_id,$c_id)
    {
        return $this->mShopBusiness->YptBusinessShopList($business_id,$c_id);
    }

    /**
     * 商家商品列表分类
     * @param $business_id
     * @return mixed
     */
    public function YptShopSort($business_id)
    {
        return $this->mShopProduct->YptShopSort($business_id);
    }

    /**
     * 商品详情
     * @param $product_id
     * @return mixed
     */
    public function YptShopDetails($product_id)
    {
        return $this->mShopProduct->YptShopDetails($product_id);
    }

    /**
     * 商品详情规格
     * @param $spec_id
     * @return mixed
     */
    public function YptShopDetailsSpec($sort_id)
    {
        return $this->mShopProduct->YptShopDetailsSpec($sort_id);
    }

    /**
     * 购物车
     * @param $user_id
     * @return mixed
     */
    public function YptShopCart($user_id)
    {
        return $this->mShopCart->YptShopCart($user_id);
    }

    /**
     * 购物车商品数
     * @param $user_id
     * @return mixed
     */
    public function YptShopCartCount($user_id)
    {
        return $this->mShopCart->YptShopCartCount($user_id);
    }

    /**
     * 购物车单个删除
     * @param $cart_id
     * @return int
     */
    public function CartDelOne($cart_id)
    {
        return $this->mShopCart->delete(['cart_id' => $cart_id]);
    }

    /**
     * 清空购物车
     * @param $user_id
     * @return int
     */
    public function CartDelAll($user_id)
    {
        return $this->mShopCart->delete(['user_id' => $user_id]);
    }

    /**
     * 购物车查询
     * @param $product_id
     * @param $user_id
     * @return mixed
     */
    public function CartSel($product_id,$s_id,$brand_id,$user_id)
    {
        return $this->mShopCart->CartSel($product_id,$s_id,$brand_id,$user_id);
    }

    /**
     * 添加购物车
     * @param $paramObj
     * @return int
     */
    public function CartAdd($paramObj,$user_id)
    {
        $aData=[
            'product_id' => $paramObj->product_id,
            'spec_id'    => $paramObj->s_id,
            'brand_id'   => $paramObj->brand_id,
            'number'     => $paramObj->num,
            'a_price'    => $paramObj->a_price,
            'user_id'    => 1,
        ];

        return $this->mShopCart->insert($aData);
    }

    /**
     * 购物车添加
     * @param $info
     * @param $paramObj
     * @param $user_id
     * @return bool
     */
    public function CartUp($info,$paramObj,$user_id)
    {
        $aData=[
            'number'     => $paramObj->num+$info->number,
            'a_price'    => $paramObj->a_price+$info->a_price,
        ];

        return $this->mShopCart->update($aData,['user_id'=>1,'product_id'=>$paramObj->product_id,'spec_id'=>$paramObj->s_id,'brand_id'=>$paramObj->brand_id]);
    }




    /**
     *商城广告位
     */
    public function AdvertPosit()
    {
        return $this->mShopad->AdsList();
    }

}